<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container a {
            color: purple;
            text-decoration: underline;
            margin-left: 20px;
        }

        .container .colum {
            display: flex;
        }
    </style>
</head>

<body>
    <div class="context">
        本站提供的图书有：
        <div class="container"></div>
    </div>

    <script>
        const strArr = [
            'java开发基础',
            'Java开发进阶',
            'Mysql开发基础',
            'JavaWeb开发技术',
            'SSM企业级开发']
        const container = document.querySelector('.container')
        container.innerHTML = strArr.map((item, index) => {
            return `<div class='colum'><div class='con${index}'>${item}</div> 
                    <a href="#" class="cona${index}">点击购买</a></div>
                    </br>`;
        }).join('');
        let storageArr = JSON.parse(localStorage.getItem('str')) || []
        for (let i = 0; i < strArr.length; i++) {
            const aClick = document.querySelector(`.cona${i}`)
            aClick.addEventListener('click', () => {
                const str = document.querySelector(`.con${i}`).innerHTML
                storageArr.push(str)
                localStorage.setItem('str', JSON.stringify(storageArr))
                console.log(storageArr);
                location.href = './list.html'
            })
        }
    </script>
</body>

</html>